package com.excilys.formation.project.restful.resources;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import com.excilys.formation.project.dtos.ClientDTO;
import com.excilys.formation.project.entities.Client;
import com.excilys.formation.project.services.ClientService;

@Component("clientResource")
@Path("/clientservice")
public class ClientResource implements IClientService {

	@Autowired
	@Qualifier("client2ClientDTOConverter")
	private Converter<Client, ClientDTO> converter;

	@Autowired
	private ClientService clientservice;

	@Override
	@GET
	@Path("/client/{login}")
	@Produces("application/xml")
	public ContainerList getClientByName(@PathParam("login") String login) {
		ContainerList maListe = new ContainerList();

		Client client = clientservice.getClient(login);
		ClientDTO clientDTO = converter.convert(client);
		maListe.yourlist.add(clientDTO);
		return maListe;
	}

	@Override
	@GET
	@Path("/client/{login}")
	@Produces("application/json")
	public ContainerList getClientJsonByName(@PathParam("login") String login) {
		ContainerList maListe = new ContainerList();

		ClientDTO cDTO = new ClientDTO();
		Client realClient = clientservice.getClient(login);
		cDTO.setLogin(realClient.getLogin());
		cDTO.setNom(realClient.getNom());
		cDTO.setPrenom(realClient.getPrenom());
		maListe.yourlist.add(cDTO);
		return maListe;
	}
	@Override
	@POST
	@Path("/newclient")
	public void newVirement() {
		
		System.out.println("*********  We have successfully posted!!!! **********");
		
	}

}
